/*
 * 
 * LegendShop 多用户商城系统
 * 
 *  版权所有,并保留所有权利。
 * 
 */
package com.legendshop.oa.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.legendshop.dao.criterion.MatchMode;
import com.legendshop.dao.sql.ConfigCode;
import com.legendshop.dao.support.CriteriaQuery;
import com.legendshop.dao.support.PageSupport;
import com.legendshop.dao.support.QueryMap;
import com.legendshop.dao.support.SimpleSqlQuery;
import com.legendshop.dao.support.lambda.LambdaQueryMap;
import com.legendshop.oa.dao.AdminUserDao;
import com.legendshop.oa.dto.AdminUserTaskEstimateDto;
import com.legendshop.oa.dto.Select2Dto;
import com.legendshop.oa.model.AdminUser;
import com.legendshop.oa.model.Role;
import com.legendshop.permission.service.AdminUserService;

import java.util.Date;
import java.util.List;

/**
 * 用户服务.
 */
public class AdminUserServiceImpl  implements AdminUserService{
	
    private AdminUserDao adminUserDao;

    public AdminUser getAdminUser(Long id) {
        return adminUserDao.getAdminUser(id);
    }

    public void deleteAdminUser(AdminUser adminUser) {
        adminUserDao.deleteAdminUser(adminUser);
    }

    public Long saveAdminUser(AdminUser adminUser) {
        return adminUserDao.saveAdminUser(adminUser);
    }

    public void updateAdminUser(AdminUser adminUser) {
        adminUserDao.updateAdminUser(adminUser);
    }

    public void setAdminUserDao(AdminUserDao adminUserDao) {
        this.adminUserDao = adminUserDao;
    }

	@Override
	public Boolean isAdminUserExist(String userName) {
		return adminUserDao.isAdminUserExist(userName);
	}

	@Override
	public int updateAdminUserPassword(Long id, String newPassword) {
		return adminUserDao.updateAdminUserPassword(id, newPassword);
		
	}

	@Override
	public List<Role> loadRole(String appNo) {
		return adminUserDao.loadRole(appNo);
	}

	@Override
	public List<Role> loadRole(Long userId, String appNo) {
		return adminUserDao.loadRole(userId, appNo);
	}

	@Override
	public PageSupport<AdminUser> getAdminUser(String curPageNO, AdminUser adminUser) {
		return adminUserDao.getAdminUser(curPageNO,adminUser);

	}

	/**
	 * 获取用户列表
	 */
	@Override
	public JSONObject userList(String q, Integer pageSize, Integer currPage) {
		List<Select2Dto> list = adminUserDao.userList(q, pageSize, currPage);
		int total = adminUserDao.userCount(q);
		JSONObject result = new JSONObject();
		result.put("results", list);
		result.put("total", total);
		return result;
	}

	/**
	 * 获取用户列表
	 */
	@Override
	public JSONObject userListForMyColleague(boolean isAdmin, String q, Integer pageSize, Integer currPage, String leaderName) {
		List<Select2Dto> list = adminUserDao.userListForMyColleague(isAdmin, q, pageSize, currPage, leaderName);
		int total = adminUserDao.userCountForMyColleague(isAdmin, q, leaderName);
		JSONObject result = new JSONObject();
		result.put("results", list);
		result.put("total", total);
		return result;
	}

	@Override
	public JSONObject userListForTeam(Long projectId, String q, Integer pageSize, Integer currPage) {
		List<Select2Dto> list = adminUserDao.userListForTeam(projectId, q, pageSize, currPage);
		int total = adminUserDao.userListForTeamCount(projectId ,q);
		JSONObject result = new JSONObject();
		result.put("results", list);
		result.put("total", total);
		return result;
	}

	@Override
	public JSONObject userListInTeam(Long projectId, String q, Integer pageSize, Integer currPage) {
		List<Select2Dto> list = adminUserDao.userListInTeam(projectId, q, pageSize, currPage);
		int total = adminUserDao.userListInTeamCount(projectId ,q);
		JSONObject result = new JSONObject();
		result.put("results", list);
		result.put("total", total);
		return result;
	}

	@Override
	public AdminUser getAdminUserByUserName(String userName) {
		return adminUserDao.getAdminUserByUserName(userName);
	}

	@Override
	public boolean isUserExist(String userName) {
		return adminUserDao.isAdminUserExist(userName);
	}

	@Override
	public PageSupport<AdminUser> getAdminUserByDept(String curPageNO, AdminUser adminUser, Date startDate, Date endDate) {
		return adminUserDao.getAdminUserByDept(curPageNO, adminUser, startDate, endDate);
	}

	@Override
	public List<AdminUserTaskEstimateDto> getAdminUserTaskEstimate(String userName, Date startDate, Date endDate) {
		return adminUserDao.getAdminUserTaskEstimate(userName, startDate,endDate);
	}
}
